package com.ldr.custom.spring.enums;

import com.ldr.custom.spring.strategy.IntegerConvertStrategy;
import com.ldr.custom.spring.strategy.LongConvertStrategy;
import com.ldr.custom.spring.strategy.StringConvertStrategy;

/**
 * 转换枚举
 */
public enum ConvertStrategyEnum {

    INTEGER(Integer.class, IntegerConvertStrategy.class),
    STRING(String.class,  StringConvertStrategy.class),
    LONG(Long.class,  LongConvertStrategy.class),
    LONGARRAY(Long[].class, LongConvertStrategy.class);


    private Object type;
    private Class convertStrategy;

    private ConvertStrategyEnum(Object type, Class convertStrategy) {
        this.type = type;
        this.convertStrategy = convertStrategy;
    }

    public static Class<?> findObjByType(Class<?> type) {

        for (ConvertStrategyEnum value : values()) {
            if (value.type.equals(type)) {
//                boolean isSupport = value.convertStrategy.isSupport(value.convertStrategy);
//                if (!isSupport){
//                    throw new RuntimeException("转换策略不匹配");
//                }
//                return value.convertStrategy;

               return value.convertStrategy;
            }
        }
        return null;
    }


}
